#include <stdio.h>
#include <sqlite3.h>

int callback(void* arg, int f_num, char** f_value, char** f_name)
{
    for (int i = 0; i < f_num; i++)
    {
        printf("%s:%s\n",f_name[i],f_value[i]);
    }
    printf("\n");
    return SQLITE_OK;
    
}

int main(int argc, char const *argv[])
{
    sqlite3* db = NULL;
    int ret = sqlite3_open("1.db",&db);
    if (ret != SQLITE_OK)
    {
        printf("sqlite3_open err\n");
        return 0;
    }

    printf("open success\n");

    char buf[256] = "select * from stu;";

    char* errmsg = NULL;
    ret = sqlite3_exec(db,buf,callback,NULL,&errmsg);
    if (ret!=SQLITE_OK)
    {
        printf("err = %s\n",errmsg);
        sqlite3_free(errmsg);
        return -1;
    }
    

    sqlite3_close(db);

    printf("close success\n");
      
    return 0;
}
